package com.gxa.logistics.controller;


import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.*;
import com.gxa.logistics.domain.vo.MessionVO;
import com.gxa.logistics.domain.vo.VehicleVO;
import com.gxa.logistics.service.MessionService;
import com.gxa.logistics.service.VehicleService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;

@Api(tags = "车辆管理—任务列表")
@RestController
@RequestMapping("/vehicle_mession")
@Slf4j
public class MessionController {

    @Autowired
    private MessionService messionService;

    /**
     * 获取用户列表
     */
    @ApiOperation(value = "获取任务列表-分页", notes = "获取任务列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页码数", defaultValue = "1", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", defaultValue = "10", paramType = "query", dataType = "String")
    })
    @GetMapping("/list")
    public RespResult<PageWrapperDTO<MessionVO>> list(MessionReqListDTO messionReqListDTO) {
        return messionService.list(messionReqListDTO);
    }

    /**
     * 新增车辆
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data", value = "系统用户添加实体") @Validated MessionSaveDTO messionSaveDTO) {
        // 保存
        messionService.insertMession(messionSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data", value = "车辆修改实体") MessionUpdateDTO messionUpdateDTO) {
        messionService.updateMession(messionUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除用户
     */
    /**
     * 删除用户
     */
    @ApiOperation(value = "删除车辆任务", notes = "删除车辆任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lpnum", value = "车牌号码", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "date", value = "日期", required = true, dataType = "Date", paramType = "query")
    })
    @PostMapping("/delete/{lpnum}")
    public RespResult delete(@PathVariable String lpnum, @RequestParam("date") Date date) {
        messionService.deleteMessionByLpnumAndDate(lpnum, date);
        return RespResult.success();
    }
}

